﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace WordMine
{
    class Base : GameObject
    {
        public int x;
        public int y;
        public Rectangle sourceRect;
        public int totalFrames;
        public int rows;
        public int columns;
        public int imageCode;
        public int attackspeed;
        public int milliseconds;
        public Boolean finished;
        public Boolean goingUp;
        public int currentFrame;
        public Symbol symbol;
        public int positionChange;
        public int hp;
        public int ap;

        public Base(Vector2 position)
            : base("foreground/wall", position)
        {
            hp = 1000;
            ap = 10;
            attackspeed = 0;
            zindex = .2f;
        }

        public override void LoadContent(ContentManager content)
        {
            base.LoadContent(content);
            this.sourceRect = new Rectangle(0, 0, this.texture.Width, this.texture.Height);
            
            this.rectangle.X = (int)this.position.X - sourceRect.Width / 2;
            this.rectangle.Y = (int)this.position.Y - sourceRect.Height / 2;
            this.rectangle.Width = sourceRect.Width;
            this.rectangle.Height = sourceRect.Height;
        }
        public void checkEnemy(Unit unit)
        {
            if (unit.rectangle.Intersects(rectangle))
            {
                unit.milliseconds = 2;
                if(attackspeed--<=0)
                    swingSword(unit);
            }
        }
        public void swingSword(Unit unit)
        {
            attackspeed = 100;
            unit.hp -= ap;
            hp -= unit.ap;
            Console.WriteLine(hp);
        }
        public override void Update(GameTime gameTime)
        {
                milliseconds--;
                if (milliseconds < 0)
                {
                    milliseconds = 10;
                    base.Update(gameTime);
                }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            if (this.visible)
            {
                if (this.texture != null)
                {
                    spriteBatch.Draw(this.texture, this.position, this.sourceRect, this.tintColor, this.rotation, new Vector2(sourceRect.Width / 2, sourceRect.Height / 2), 1, SpriteEffects.None, this.zindex);
                }
            }
        }
    }
}
